package com.alibaba.algo.controller.app;

import com.alibaba.algo.annotation.OperateLogAnnotation;
import com.alibaba.algo.apiimpl.app.AppAccountServiceImpl;
import com.alibaba.algo.cooperation.common.BaseResult;
import com.alibaba.algo.cooperation.usercenter.GlobalResultStatus;
import com.alibaba.algo.cooperation.usercomponent.vo.req.app.DeleteAppAccountRequestVO;
import com.alibaba.algo.cooperation.usercomponent.vo.req.app.SelectAppAccountRequestVO;
import com.alibaba.algo.enums.OperateTypeEnum;
import com.alibaba.algo.enums.ResourceTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类AppAccountController.java的实现描述：应用账号 Controller
 *
 * @author nieganggang 2021-03-12 16:08:17
 */
@RestController
@RequestMapping(value = "/usercenter-admin-app/admin/appAccount")
public class AppAccountController {

    @Autowired
    private AppAccountServiceImpl appAccountService;

    @PostMapping("/delete")
    @OperateLogAnnotation(resouceType = ResourceTypeEnum.APP_ACCOUNT,operateType = OperateTypeEnum.DELETE)
    public BaseResult delete(@RequestBody DeleteAppAccountRequestVO vo) {
        if (StringUtils.isEmpty(vo.getId())) {
            return BaseResult.buildError(GlobalResultStatus.PARAM_APP_ACCOUNT_ID_ERROR.getCode(), GlobalResultStatus.PARAM_APP_ACCOUNT_ID_ERROR.getMsg());
        }
        return appAccountService.delete(vo);
    }

    @PostMapping("/selectList")
    public BaseResult selectList(@RequestBody SelectAppAccountRequestVO vo) {
        if (ObjectUtils.isEmpty(vo.getAppId())) {
            return BaseResult.buildError(GlobalResultStatus.PARAM_APP_ID_ERROR.getCode(), GlobalResultStatus.PARAM_APP_ID_ERROR.getMsg());
        }
        return appAccountService.selectList(vo);
    }

}
